﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;

namespace SM2WelcomePage
{
    public class WelcomePage
    {
        public static void loginValidate()
        {
            //Prepare data
            string stringUserName = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Username");
            string stringPassword = SM2TestRunner.TestDispatcher.TEST_PARAMETER.get("Password");

            //TO-DO
            SM2Input.Tradition.TypeTextFieldBYID("Login1_UserName", stringUserName);
            SM2Input.Tradition.TypePasswordBYID("Login1_Password", stringPassword);
            SM2Input.Tradition.ClickButtonBYID("Login1_LoginButton");
            Utilities.GlobalObject.MANAGER.ActiveBrowser.WaitUntilReady();
            Utilities.Validation.validateTextPresentInPage(Utilities.GlobalTestStep.strValidation);
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_TIMEOUT_MILISECOND);
            Utilities.GlobalObject.SILVERLIGHTAPP = Utilities.GlobalObject.MANAGER.ActiveBrowser.SilverlightApps()[0];
        }

        public static void loginSuccess()
        {
            //TO-DO
            SM2Input.Tradition.TypeTextFieldBYID("Login1_UserName", Utilities.GlobalRunning.SERVER_USER);
            SM2Input.Tradition.TypePasswordBYID("Login1_Password", Utilities.GlobalRunning.SERVER_PASSWORD);
            SM2Input.Tradition.ClickButtonBYID("Login1_LoginButton");
            Utilities.GlobalObject.MANAGER.ActiveBrowser.WaitUntilReady();
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_TIMEOUT_MILISECOND);
            try
            {
                SilverlightAppsList slist = Utilities.GlobalObject.MANAGER.ActiveBrowser.SilverlightApps();
                Utilities.GlobalObject.SILVERLIGHTAPP = slist[0];
            }
            catch (Exception EX) { string str = EX.ToString(); }
        }

        public static void loginSuccess(string strUser, string strPwd)
        {
            //TO-DO
            SM2Input.Tradition.TypeTextFieldBYID("Login1_UserName", strUser);
            SM2Input.Tradition.TypePasswordBYID("Login1_Password", strPwd);
            SM2Input.Tradition.ClickButtonBYID("Login1_LoginButton");
            Utilities.GlobalObject.MANAGER.ActiveBrowser.WaitUntilReady();
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_TIMEOUT_MILISECOND);
            try
            {
            SilverlightAppsList slist = Utilities.GlobalObject.MANAGER.ActiveBrowser.SilverlightApps();
            Utilities.GlobalObject.SILVERLIGHTAPP = slist[0];
            }
            catch { }
        }

        public static void logoff()
        {
            SM2Input.Tradition.ClickAnchorBYID("ctl05_LoginStatus1");
            Utilities.GlobalObject.MANAGER.ActiveBrowser.WaitUntilReady();
            System.Threading.Thread.Sleep(Utilities.GlobalConfig.INT_WAIT_INTERVAL_MILISECOND);
        }
    }
}
